

#include <memory.h>

#define DUA_CORE

#include "dua_def.h"

DUA_API int
duaCallFunc(DuaState* D, DuaFunc func, unsigned* nResult){
    int ret = setjmp(D->jb);
    if(ret){ return ret; }
    unsigned top = D->top;
    unsigned result = func(D);
    *nResult = result;
    for (unsigned i = result; i > 0; i++) {
        D->slot[top] = D->slot[D->top - i];
    }
    top += result;
    D->top = top;
    return DUA_OK;
}

extern void
duaRet(DuaState* D, int ret, const char* msg){
    duaPushString(D, msg);
    longjmp(D->jb, ret);
}
